<?php
/**
 * @since v1.0
 * @modify 2015.6.21
 * @copyright 深圳亿游
 */
require_once(LIB_PATH.'controller/root.con.php');

class subjectCon extends rootCon
{
        //@todo 使用缓存
        public function listAction(){
            $list = myredis::getArray("subjectList");
            if($list){
                $this->j(0, "cache",$list);
            }

            //教学方向
            $obj = new Subject();
            $result = $obj->all(['status'=>3]);
            $ret['subject'] = $result;
			
            //机构类别
            $obj = new SchoolType();
            $result = $obj->all(['status'=>3]);
            $i = 0;
            foreach($result as $item){
                $mainId = $item['schoolTypeId'];
                $type2 = new SchoolType2();
                $subAll = $type2->all(['schoolTypeId',$mainId]);
                $result[$i]['subType'] = $subAll;
                $i++;
            }
            $ret['schoolType'] = $result;

            //城市
            $obj = new City();
            $result = $obj->all(['status'=>3]);
            $ret['city'] = $result;

           /* $obj = new TeacherType();
            $result = $obj->all(['status'=>3]);
            $ret['teacherType'] = $result;*/
            //课程主类
            $obj = new CourseMain();
            $result = $obj->all(['status',STATUS_PUBLISH],'`sort` ASC');
	
	        // 课程子类
            $obj = new CourseSub();
            $sub = $obj->all(['status',STATUS_PUBLISH],'`sort` ASC');
            foreach($sub as $row){
                for($i = 0; $i < count($result); $i++){
                    if($row['courseMainId']==$result[$i]['courseMainId']){
                        $row['courseMain'] =  $row['courseSub'];
                        $result[$i]['sub'][] = $row;
                    }
                }
            }

            $ret['courseMain'] = $result;

            //教师标签
            $obj = new Label();
            $result = $obj->all(['status'=>3]);
            $ret['label'] = $result;

            //办学形式
            $obj = new SchoolSort();
            $result = $obj->all(['status'=>3]);
            $ret['schoolSort'] = $result;

            //机构标签
            $obj = new Tag();
            $result = $obj->all(['status'=>3],'tagSort ASC');
            $ret['tag'] = $result;

            //学历
            $obj = new Level();
            $result = $obj->all(['status'=>3],'weight DESC');
            $ret['level'] = $result;

            //国籍
            $obj = new Nation();
            $result = $obj->all(['status'=>3],'weight DESC');
            $ret['nation'] = $result;

            //办学规模
            $obj = new SchoolScale();
            $result = $obj->all(['status'=>3]);
            $ret['schoolScale'] = $result;


            myredis::setArray("subjectList",$ret,600);

            $this->j(0, "db",$ret);
    }
}



